/**
 * 
 */
package vn.edu.fpt.xml.hrm.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Yoshimi
 *
 */
public class MainController extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -11228835859287661L;

	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// Same as do post
		doPost(req, resp);
	}

	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		String action = null;
		String targetPage = null;
		action = req.getParameter("action");
		if ("Say Hello World".equals(action)) {
			targetPage = executeHelloWorldAction(req, resp);
		}
		req.getRequestDispatcher(targetPage).forward(req, resp);
	}

	private String executeHelloWorldAction(HttpServletRequest req,
			HttpServletResponse resp) {
		// TODO Auto-generated method stub
		req.setAttribute("name", req.getParameter("name"));
		return "jsp/helloWorld.jsp";
	}

}
